define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/bill/index' + location.search,
                    add_url: 'shop/bill/add',
                    edit_url: 'shop/bill/edit',
                    del_url: 'shop/bill/del',
                    multi_url: 'shop/bill/multi',
                    import_url: 'shop/bill/import',
                    table: 'shop_bill',
                }
            });

            var table = $("#table");

            //当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#sum_des_sale").text(data.extend.sum_des_sale);
                $("#sum_des_number").text(data.extend.sum_des_number);
                $("#sum_des_money").text(data.extend.sum_des_money);
                $("#sum_des_scale").text(data.extend.sum_des_scale);

                $("#sum_sport_sale").text(data.extend.sum_sport_sale);
                $("#sum_sport_number").text(data.extend.sum_sport_number);
                $("#sum_sport_money").text(data.extend.sum_sport_money);
                $("#sum_sport_scale").text(data.extend.sum_sport_scale);

                $("#sum_rtw_sale").text(data.extend.sum_rtw_sale);
                $("#sum_rtw_number").text(data.extend.sum_rtw_number);
                $("#sum_rtw_money").text(data.extend.sum_rtw_money);
                $("#sum_rtw_scale").text(data.extend.sum_rtw_scale);

                $("#sum_fre_sale").text(data.extend.sum_fre_sale);
                $("#sum_fre_number").text(data.extend.sum_fre_number);
                $("#sum_fre_money").text(data.extend.sum_fre_money);
                $("#sum_fre_scale").text(data.extend.sum_fre_scale);

                $("#sum_acc_sale").text(data.extend.sum_acc_sale);
                $("#sum_acc_number").text(data.extend.sum_acc_number);
                $("#sum_acc_money").text(data.extend.sum_acc_money);
                $("#sum_acc_scale").text(data.extend.sum_acc_scale);

                $("#sum_ttl_sale").text(data.extend.sum_ttl_sale);
                $("#sum_ttl_number").text(data.extend.sum_ttl_number);
                $("#sum_ttl_money").text(data.extend.sum_ttl_money);


                $("#sum_task").text(data.extend.sum_task);
                $("#sum_ridership").text(data.extend.sum_ridership);
                $("#scale").text(data.extend.scale);

            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'date',
                fixedColumns: true,
                fixedRightNumber: 5,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),visible: false},
                        {field: 'des_sale', title: __('DES单'), operate:'BETWEEN',sortable: true},
                        {field: 'des_number', title: __('DES件'), operate:'BETWEEN',sortable: true},
                        {field: 'des_money', title: __('DES金额'), operate:'BETWEEN',sortable: true},
                        {field: 'sport_sale', title: __('SPO单'), operate:'BETWEEN',sortable: true},
                        {field: 'sport_number', title: __('SPO件'), operate:'BETWEEN',sortable: true},
                        {field: 'sport_money', title: __('SPO金额'), operate:'BETWEEN',sortable: true},
                        {field: 'rtw_sale', title: __('RTW单'), operate:'BETWEEN',sortable: true},
                        {field: 'rtw_number', title: __('RTW件'), operate:'BETWEEN',sortable: true},
                        {field: 'rtw_money', title: __('RTW金额'), operate:'BETWEEN',sortable: true},
                        {field: 'fre_sale', title: __('FRE单'), operate:'BETWEEN',sortable: true},
                        {field: 'fre_number', title: __('FRE件'), operate:'BETWEEN',sortable: true},
                        {field: 'fre_money', title: __('FRE金额'), operate:'BETWEEN',sortable: true},
                        {field: 'acc_sale', title: __('ACC单'), operate:'BETWEEN',sortable: true},
                        {field: 'acc_number', title: __('ACC件'), operate:'BETWEEN',sortable: true},
                        {field: 'acc_money', title: __('ACC金额'), operate:'BETWEEN',sortable: true},
                        {field: 'ttl_sale', title: __('总单'), operate:'BETWEEN',sortable: true},
                        {field: 'ttl_number', title: __('总件'), operate:'BETWEEN',sortable: true},
                        {field: 'ttl_money', title: __('总金额'), operate:'BETWEEN',sortable: true},
                        {field: 'upt', title: __('UPT(总件/总单)'), operate:'BETWEEN',sortable: true},
                        {field: 'remark', title: __('备注'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},


                        {field: 'create_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'update_time', title: __('修改时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'admin_id', title: __('Admin_id'), formatter:Table.api.formatter.search},

                        {field: 'task', title: __('每日任务'), operate:'BETWEEN',sortable: true},
                        {field: 'ridership', title: __('客流量'), operate:'BETWEEN',sortable: true},
                        {field: 'date', title: __('日期'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,sortable: true},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
